//
//  TestViewController.swift
//  AliBaiChuan
//
//  Created by 郑东喜 on 2017/2/22.
//  Copyright © 2017年 郑东喜. All rights reserved.
//  测试界面

import UIKit

class TestViewController: UIViewController {
    
    var _window             :UIWindow!

    lazy var btn: UIButton = {
        let btn : UIButton = UIButton.init(frame: CGRect.init(x: 100, y: 100, width: 100, height: 100))
        btn.backgroundColor = UIColor.blue
        return btn
    }()
    
    lazy var shopName: UILabel = {
        let tt : UILabel = UILabel.init(frame: CGRect.init(x: 0, y: 100, width: SW, height: 40))
        
        tt.text = "啊说来就大姐大色季拉山级大神解答时；就打算的阿来得及拉丝机大山里的骄傲圣诞节圣诞节三就啊说来就大姐大色季拉山级大神解答时；就打算的阿来得及拉丝机大山里的骄傲圣诞节圣诞节三就啊说来就大姐大色季拉山级大神解答时；就打算的阿来得及拉丝机大山里的骄傲圣诞节圣诞节三就啊说来就大姐大色季拉山级大神解答时；就打算的阿来得及拉丝机大山里的骄傲圣诞节圣诞节三就"
        
        tt.numberOfLines = 0
        tt.lineBreakMode = .byCharWrapping
        tt.layer.borderWidth = 1
        
        ///获取实时文本的大小
        let addSize : CGSize = tt.sizeThatFits(CGSize(width: tt.frame.size.width, height: CGFloat(MAXFLOAT)))
        
        tt.frame = CGRect(x: tt.frame.origin.x, y: tt.frame.origin.y, width: tt.frame.size.width, height: addSize.height)
        
        tt.sizeToFit()
        
        return tt
    }()
    
    lazy var scrollView: UIScrollView = {
        let scV : UIScrollView = UIScrollView.init(frame: self.view.bounds)
        scV.backgroundColor = .gray
        scV.delegate = self;
        scV.contentSize = CGSize.init(width: SW, height: SH * 2)
        return scV
    }()
    
    
    lazy var labelNormal: UILabel = {
        let a : UILabel = UILabel.init(frame: CGRect.init(x: 0, y: 100, width: SW, height: 55))
        a.text = "dalskdjasldjalsjdlsajdajdlasjdlkajdlajdlkasjdlkasjd;lajd;lkasjd;alsjds"
        a.layer.borderWidth = 1
        a.sizeToFit()
        return a
    }()
    

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        view.addSubview(shopName)
        
        view.addSubview(scrollView)
        
//        show()
        
//        view.addSubview(labelNormal)
    }

}


extension TestViewController {
    func show() {
        _window = UIWindow.init(frame: CGRect.init(x: 100, y: 100, width: 100, height: 100))
        _window.windowLevel = UIWindowLevelAlert + 1
        _window.backgroundColor = UIColor.black
        _window.isHidden = true
        _window.isUserInteractionEnabled = true
 
        _window.addSubview(self.view)
        
        _window.isHidden = false
        
        _window.addSubview(self.btn)
    }
}

extension TestViewController : UIScrollViewDelegate {
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        if scrollView.contentOffset.y > 100 {
            show();
        } else {
            dismiss();
        }
    }
    
    fileprivate func dismiss() -> Void {
        _window = nil
    }
}
